package IC.lir;

import java.util.ArrayList;
import java.util.List;
import IC.Constants;
import IC.AST.Method;
import IC.lir.instructions.Instruction;
import IC.lir.instructions.Label;

/**
 * 
 * LIRMethod Object
 *
 */
public class LIRMethod extends LIRObject {
	
	private Method AstMethod;
	private List<Instruction> Instructions;
	
	//C'tor
	public LIRMethod(Method AstMethod, LIRClass parent)
	{
		super(parent);
		this.AstMethod = AstMethod;
		
		String AstMethodName = this.AstMethod.getName();
		if (!AstMethodName.equals("main")) 
			this.Label = new Label("_" + parent.getName() + "_" + AstMethodName);
		 else 
			this.Label = new Label("_ic_main");
		
		Instructions = new ArrayList<Instruction>();
	}
	
	public Method getAstMethod() {
		return AstMethod;
	}
	
	public List<Instruction> getInstructions() {
		return Instructions;
	}

	@Override
	public String toString() {
		StringBuffer s = new StringBuffer();
		for (Instruction i : Instructions)
			s.append(i + Constants.LINE_BREAK);
		return s.toString();
	}
	
}
